package com.orkasgb.framework.springsecurity;

import com.alibaba.fastjson2.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * 自定义通用返回格式
 *
 * @param <T> 接受一个泛型
 */
@Data
@AllArgsConstructor(staticName = "create")
public class CommonResult<T> {

    private int code;
    private String message;
    private T data;

    public static <T> CommonResult<T> ofSuccess(T data, String message) {
        return create(0,  message, data);
    }

    public static <T> CommonResult<T> ofFailure(String message) {
        return create(1,  message, null);
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
